//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    preTitle: '',
    title: '习题',
    _title: '习题',
    examType: {
      11: 'choice',
      12: 'mchoice',
      13: 'tfChoice',
      21: 'blanks'
    },
    papers: [],
    types: [],
    currPaper: {},
    currType: 'choice'
  },
  onLoad: function () {
    const num = wx.getStorageSync('modNum')
    let _type = []
    const _paper = app.globalData.questions.map((v) => {
      _type.push({
        index: v.type.type,
        name: v.type.name
      })
      v.question.answer1 = v.question.id
      return v.question
    })
    this.setData({
      types: _type,
      papers: _paper,
      currPaper: _paper[0],
      preTitle: _type[num].name,
      currType: this.data.examType[_type[num].index],
      title: this.data._title + this.covertZhNum(num)
    })
  },
  covertZhNum: function(num) {
    const AA = ['一', '二', '三', '四', '五', '六', '七', '八', '九']
    return AA[num]
  },
  getStudentId: function (e) {
   
  },
  onStepSubmit: function (e) {
    const complete = e.detail.complete || false
    if (complete) {
      //考试完成，提交总成绩
      const daAn = wx.getStorageSync('totalAnswer') //获取答卷结果
      const studentId = wx.getStorageSync('stuId')//获取学生id
      const paperId = wx.getStorageSync('paperId') //获取试卷id
      const result = {
        student_id: studentId,
        relation_exam_exam_paper_id: paperId,
        questions: daAn
      }
      //提交总成绩
      app.apis().postExamPaper(result).then((res) => {
        wx.setStorageSync('paperResultInfo', res.paper) //返回总成绩
      })
      wx.navigateTo({
        url: '/pages/result/result'
      })
      return
    }
    const num = e.detail.value || 0
    wx.setStorageSync('modNum', num)
    this.setData({
      preTitle: this.data.types[num].name,
      currType: this.data.examType[this.data.types[num].index],
      currPaper: this.data.papers[num],
      title: this.data._title + this.covertZhNum(num)
    })
    console.log('@父键方法', e.detail)
  }
})
